package helper.request.contacts;

import helper.response.AdminandSearchResponse;
import java.sql.*;
import java.util.ArrayList;
import server.dbconnector.DatabaseConnector;

import base.User;

public class SearchUserRequest implements ContactRequest{
	private static final long serialVersionUID = 6813994014438399346L;
	private User currentuser;
	private String targetname;
	private ArrayList<User> samenameList;
	public SearchUserRequest(User current,String name){
		this.currentuser=current;
		this.targetname=name;
	}
	
	@Override
	public User gettargetuser() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int gettargetuserid() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public User getcurrentuser() {
		// TODO Auto-generated method stub
		return currentuser;
	}

	@Override
	public int getcurrentuserid() {
		// TODO Auto-generated method stub
		return currentuser.getid();
	}
	@Override
	public boolean execute() {
		// TODO Auto-generated method stub
		return false;
	}
	@Override
	public void process(DatabaseConnector dc) throws SQLException{
		samenameList=new ArrayList<User>();
		ResultSet rs=dc.query("select * from user where realname='"+this.targetname+"'");
		if(rs.first()){
			while(true){
				samenameList.add(new User(rs.getInt(1),rs.getString(2),"",rs.getString(4),rs.getInt(5),rs.getString(6),rs.getString(7), false));
				if(!rs.next())break;
			}
		}
	}
    public AdminandSearchResponse process(DatabaseConnector dc,int empty)throws Exception{
    	process(dc);
    	AdminandSearchResponse asr=new AdminandSearchResponse(samenameList);
    	return asr;
    }
}
